package com.ylc.vadator.controller;

import com.ylc.vadator.model.Customer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.validation.Valid;

/**
 * Created by yuanlichao on 2017/8/19 0019.
 */
@Controller
@RequestMapping("/customer")
public class SignUpController {

    @RequestMapping(value = "signup", method = RequestMethod.POST)
    public String signup(@Valid Customer customer, BindingResult result){
        if(result.hasErrors()){
            return "SignUpForm";
        }
        return "Done";
    }

    @RequestMapping(method = RequestMethod.GET)
    public String displayCustomerForm(ModelMap model) {

        model.addAttribute("customer", new Customer());
        return "SignUpForm";

    }
}
